import { Rule } from "./types";

export const ExceptionsRuleList: Rule[] = [
    {
        id: "ExceptionRaisedInUnexpectedLocation",
        descEn: "This rule reports functions which should never throw an exception. If a function exists that does throw an exception it will be reported. By default, this rule checks toString, hashCode, equals and finalize. This rule is configurable via the methodNames configuration to change the list of functions which should not throw any exceptions.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [
            {
                param: "methodNames",
                descEn: "methods which should not throw exceptions",
                descCn: "",
                defaultValue: ['equals', 'finalize', 'hashCode', 'toString'],
            }
        ],
        url: "https://detekt.dev/docs/rules/exceptions#exceptionraisedinunexpectedlocation",
    },
    {
        id: "InstanceOfCheckForException",
        descEn: "This rule reports catch blocks which check for the type of exception via is checks or casts. Instead of catching generic exception types and then checking for specific exception types the code should use multiple catch blocks. These catch blocks should then catch the specific exceptions.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#instanceofcheckforexception",
    },
    {
        id: "NotImplementedDeclaration",
        descEn: "This rule reports all exceptions of the type NotImplementedError that are thrown. It also reports all TODO(..) functions. These indicate that functionality is still under development and will not work properly. Both of these should only serve as temporary declarations and should not be put into production environments.",
        descCn: "",
        active: false,
        debt: "20min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#notimplementeddeclaration",
    },
    {
        id: "ObjectExtendsThrowable",
        descEn: "This rule reports all objects including companion objects that extend any type of Throwable. Throwable instances are not intended for reuse as they are stateful and contain mutable information about a specific exception or error. Hence, global singleton Throwables should be avoided.",
        descCn: "",
        active: false,
        debt: "10min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#objectextendsthrowable",
    },
    {
        id: "PrintStackTrace",
        descEn: "This rule reports code that tries to print the stacktrace of an exception. Instead of simply printing a stacktrace a better logging solution should be used.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#printstacktrace",
    },
    {
        id: "RethrowCaughtException",
        descEn: `This rule reports all exceptions that are caught and then later re-thrown without modification. It ignores cases:

        1.When caught exceptions that are rethrown if there is work done before that.
        2.When there are more than one catch in try block and at least one of them has some work.`,
        descCn: "",
        active: true,
        debt: "5min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#rethrowcaughtexception",
    },
    {
        id: "ReturnFromFinally",
        descEn: "Reports all return statements in finally blocks. Using return statements in finally blocks can discard and hide exceptions that are thrown in the try block. Furthermore, this rule reports values from finally blocks, if the corresponding try is used as an expression.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [
            {
                param: "ignoreLabeled",
                descEn: "ignores labeled return statements",
                descCn: "",
                defaultValue: false,
            }
        ],
        url: "https://detekt.dev/docs/rules/exceptions#returnfromfinally",
    },
    {
        id: "SwallowedException",
        descEn: `Exceptions should not be swallowed. This rule reports all instances where exceptions are caught and not correctly passed (e.g. as a cause) into a newly thrown exception.

        The exception types configured in ignoredExceptionTypes indicate nonexceptional outcomes. These by default configured exception types are part of Java. Therefore, Kotlin developers have to handle them by using the catch clause. For that reason, this rule ignores that these configured exception types are caught.`,
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [
            {
                param: "ignoredExceptionTypes",
                descEn: "exception types which should be ignored (both in the catch clause and body)",
                descCn: "",
                defaultValue: ['InterruptedException', 'MalformedURLException', 'NumberFormatException', 'ParseException'],
            },
            {
                param: "allowedExceptionNameRegex",
                descEn: "ignores too generic exception types which match this regex",
                descCn: "",
                defaultValue: "_|(ignore|expected).*",
            }
        ],
        url: "https://detekt.dev/docs/rules/exceptions#swallowedexception",
    },
    {
        id: "ThrowingExceptionFromFinally",
        descEn: "This rule reports all cases where exceptions are thrown from a finally block. Throwing exceptions from a finally block should be avoided as it can lead to confusion and discarded exceptions.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#throwingexceptionfromfinally",
    },
    {
        id: "ThrowingExceptionInMain",
        descEn: `This rule reports all exceptions that are thrown in a main method. An exception should only be thrown if it can be handled by a "higher" function.`,
        descCn: "",
        active: false,
        debt: "20min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#throwingexceptioninmain",
    },
    {
        id: "ThrowingExceptionsWithoutMessageOrCause",
        descEn: "This rule reports all exceptions which are thrown without arguments or further description. Exceptions should always call one of the constructor overloads to provide a message or a cause. Exceptions should be meaningful and contain as much detail about the error case as possible. This will help to track down an underlying issue in a better way.",
        descCn: "",
        active: true,
        debt: "5min",
        paramList: [
            {
                param: "exceptions",
                descEn: "exceptions which should not be thrown without message or cause",
                descCn: "",
                defaultValue: ['ArrayIndexOutOfBoundsException', 'Exception', 'IllegalArgumentException', 'IllegalMonitorStateException', 'IllegalStateException', 'IndexOutOfBoundsException', 'NullPointerException', 'RuntimeException', 'Throwable'],
            }
        ],
        url: "https://detekt.dev/docs/rules/exceptions#throwingexceptionswithoutmessageorcause",
    },
    {
        id: "ThrowingNewInstanceOfSameException",
        descEn: "Exceptions should not be wrapped inside the same exception type and then rethrown. Prefer wrapping exceptions in more meaningful exception types.",
        descCn: "",
        active: true,
        debt: "5min",
        paramList: [],
        url: "https://detekt.dev/docs/rules/exceptions#throwingnewinstanceofsameexception",
    },
    {
        id: "TooGenericExceptionCaught",
        descEn: "This rule reports catch blocks for exceptions that have a type that is too generic. It should be preferred to catch specific exceptions to the case that is currently handled. If the scope of the caught exception is too broad it can lead to unintended exceptions being caught.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [
            {
                param: "exceptionNames",
                descEn: "exceptions which are too generic and should not be caught",
                descCn: "",
                defaultValue: ['ArrayIndexOutOfBoundsException', 'Error', 'Exception', 'IllegalMonitorStateException', 'IndexOutOfBoundsException', 'NullPointerException', 'RuntimeException', 'Throwable'],
            },
            {
                param: "allowedExceptionNameRegex",
                descEn: "ignores too generic exception types which match this regex",
                descCn: "",
                defaultValue: "_|(ignore|expected).*",
            },
        ],
        url: "https://detekt.dev/docs/rules/exceptions#toogenericexceptioncaught",
    },
    {
        id: "TooGenericExceptionThrown",
        descEn: "This rule reports thrown exceptions that have a type that is too generic. It should be preferred to throw specific exceptions to the case that has currently occurred.",
        descCn: "",
        active: true,
        debt: "20min",
        paramList: [
            {
                param: "exceptionNames",
                descEn: "exceptions which are too generic and should not be thrown",
                descCn: "",
                defaultValue: ['Error', 'Exception', 'RuntimeException', 'Throwable'],
            }
        ],
        url: "https://detekt.dev/docs/rules/exceptions#toogenericexceptionthrown",
    },
];